package com.example.photography.adapter.group;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.example.photography.R;
import com.example.photography.adapter.MyBaseAdapter;
import com.example.photography.bean.Group_ProductBean;
import com.example.photography.bean.UrlBean;
import com.example.photography.ui.CircleImageView;
import com.example.photography.ui.MyGridView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class GroupHotAdapter extends MyBaseAdapter {

    private List<UrlBean> urlBeans;

    public GroupHotAdapter(List list, Context context) {
        super(list, context);
    }

    @Override
    public View myGetView(int position, View convertView) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.item_group_style, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Group_ProductBean group_productBean = (Group_ProductBean) list.get(position);

        Glide.with(mContext)
                .load(group_productBean.getHead_url())
                .thumbnail(Glide.with(mContext).load(R.drawable.loading))
                .apply(RequestOptions.bitmapTransform(new RoundedCorners(30)))
                .into(viewHolder.ivHead);
        viewHolder.tvName.setText(group_productBean.getName());
        viewHolder.tvDate.setText(group_productBean.getDate());
        urlBeans = JSONObject.parseArray(group_productBean.getProducts(), UrlBean.class);
        GroupPhotoAdatper groupPhotoAdatper = new GroupPhotoAdatper(urlBeans,mContext);
        viewHolder.gvProduct.setAdapter(groupPhotoAdatper);
        return convertView;
    }

    static
    class ViewHolder {
        @BindView(R.id.iv_head)
        CircleImageView ivHead;
        @BindView(R.id.tv_name)
        TextView tvName;
        @BindView(R.id.tv_date)
        TextView tvDate;
        @BindView(R.id.tv_focus)
        TextView tvFocus;
        @BindView(R.id.gv_product)
        MyGridView gvProduct;
        @BindView(R.id.iv_like)
        ImageView ivLike;
        @BindView(R.id.iv_comment)
        ImageView ivComment;
        @BindView(R.id.iv_collect)
        ImageView ivCollect;
        @BindView(R.id.iv_share)
        ImageView ivShare;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
